package com.example.zx_springboot.controller;

import com.example.zx_springboot.entity.Zxcustomer;

import com.example.zx_springboot.entity.Zxloss;
import com.example.zx_springboot.service.ZxCustomerService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class ZxCustomerController {
    @Autowired
    private ZxCustomerService zxCustomerService;

//    @GetMapping("/findpage")
//    public List<Zxcustomer> findpagecustomer() {
//        return zxCustomerService.getallcustomer();



    @GetMapping("/findByPage")
    public PageInfo findAll(@RequestParam("pageNum") Integer pageNum,
                            @RequestParam("pageSize") Integer pageSize,
                            @RequestParam("customerName") String customerName) {
        return zxCustomerService.findByPage(pageNum, pageSize,customerName);
    }
    @PostMapping("/add")
    public String addcustomer(@RequestBody Zxcustomer zxcustomer){
        zxCustomerService.addcustomer(zxcustomer);
        return "addcustomer success";
    }
    @PostMapping("/update")
    public String updatecustomer(@RequestBody Zxcustomer zxcustomer){
        zxCustomerService.updatecustomer(zxcustomer);
        return "update success";
    }
    @DeleteMapping("/delete")
    public String deletecustomer(@RequestParam("customer_num") Integer customer_num){
        zxCustomerService.deletecustomer(customer_num);
        return "delete sucs";
    }
    @PostMapping("/deletes")
    public String deletecustomers(@RequestBody List<Integer> ids){
        zxCustomerService.deletescustomer(ids);

        return "delete success";
    }
    @GetMapping("/loss")
    public List<Zxloss> losscustomer(){
        return zxCustomerService.losscustomer();
    }
    @GetMapping("/lossfindByPage")
    public PageInfo findlossAll(@RequestParam("pageNum") Integer pageNum,
                            @RequestParam("pageSize") Integer pageSize,
                            @RequestParam("customerName") String customerName) {
        return zxCustomerService.lossfindByPage(pageNum, pageSize,customerName);
    }
    @PostMapping("/updateloss")
    public String updateloss(@RequestBody Zxloss zxloss) {
        zxCustomerService.updateloss(zxloss);
        return "edit success";
    }
    @DeleteMapping("/deleteloss")
    public String deleteloss(@RequestParam("customer_id") Integer customer_id ) {
        zxCustomerService.deleteloss(customer_id);
        return "edit success";
    }
    @PostMapping("/deletelosses")
    public String deletelosses(@RequestBody List<Integer> loss_ids){
        zxCustomerService.deletelosses(loss_ids);

        return "delete success";
    }
    @PostMapping("/addloss")
    public String addloss(@RequestBody Zxloss zxloss){
        zxCustomerService.addloss(zxloss);
        return "add success";
    }
}
